package com.alibaba.algo.dao.user;

import com.alibaba.algo.cooperation.feign.vo.req.SelectAppResourceReqVO;
import com.alibaba.algo.cooperation.feign.vo.req.SelectRoleResourceActionReqVO;
import com.alibaba.algo.cooperation.feign.vo.req.SelectRoleResourceReqVO;
import com.alibaba.algo.cooperation.feign.vo.req.SelectUserResourceReqVO;
import com.alibaba.algo.cooperation.feign.vo.res.ResourceActionResVO;
import com.alibaba.algo.cooperation.feign.vo.res.ResourceResVO;
import com.alibaba.algo.cooperation.feign.vo.res.RoleResourceActionResVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectResourceListRequestVO;
import com.alibaba.algo.core.base.BaseMapper;
import com.alibaba.algo.entity.user.SysResource;
import com.alibaba.algo.entity.user.SysResourceAction;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 类SysResourceMapper.java的实现描述：资源Mapper
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
public interface SysResourceMapper extends BaseMapper<SysResource> {

    /**
     * 查询资源列表,菜单资源下的角色列表总数
     *
     * @param selectResourceListRequestVO 入参
     * @return 角色数量
     */
    Integer countByPage(@Param("obj") SelectResourceListRequestVO selectResourceListRequestVO);

    /**
     * 查询资源列表,菜单资源下的角色列表
     *
     * @param selectResourceListRequestVO 入参
     * @param start                       分页开始
     * @param end                         分页结束
     * @param sortStr                     排序字段
     * @return 角色列表
     */
    List<SysResource> selectResourcePage(
            @Param("obj") SelectResourceListRequestVO selectResourceListRequestVO, @Param("start") int start, @Param("end") int end);

    Integer selectResourcePageCount(@Param("obj") SelectResourceListRequestVO selectResourceListRequestVO);

    /**
     * 查询用户指定类型的资源列表
     *
     * @param vo               用户标识
     * @param resourceTypeList 资源类型
     * @return 用户标识
     */
    List<Long> selectResourceIdListByUserId(@Param("vo") SelectUserResourceReqVO vo, @Param("resourceTypeList") List<Integer> resourceTypeList);

    /**
     * 查询父级菜单资源
     *
     * @param childResourceId 子菜单资源标识
     * @return 父级菜单资源列表
     */
    List<Long> selectParentResourceIdListByChildId(@Param("childResourceId") Long childResourceId);

    List<SysResource> selectResourceIdListRecursiveToRoot(@Param("id") Long id);

    /**
     * 根据角色id查询菜单列表
     *
     * @param vo
     * @return
     */
    List<ResourceResVO> qryResourceListByRoleId(@Param("vo") SelectRoleResourceReqVO vo);

    /**
     * 根据角色id查询按钮列表
     *
     * @param vo
     * @return
     */
    List<RoleResourceActionResVO> qryRoleResourceActionListByRoleId(@Param("vo") SelectRoleResourceActionReqVO vo);

    /**
     * 通过租户编码或资源路径列表查询资源清单
     *
     * @param vo
     * @return
     */
    List<ResourceResVO> qryResourceListByAppOrPath(@Param("vo") SelectAppResourceReqVO vo);

    /**
     * 通过租户编码或资源路径列表查询按钮清单
     *
     * @param vo
     * @return
     */
    List<ResourceActionResVO> qryResourceActionListByAppOrPath(@Param("vo") SelectAppResourceReqVO vo);

    List<ResourceActionResVO> qryResourceActionByIdAndAppCode(@Param("resourceId") Long resourceId, @Param("appCode") String appCode);

    List<SysResourceAction> qryByResourceIdAndAppCode(@Param("resourceId") Long resourceId, @Param("appCode") String appCode);

    SysResourceAction qryByResourceActionId(@Param("resourceActionId") Long resourceActionId);

    List<SysResource> qryResourceByIds(@Param("ids") List<Long> ids);

    void deleteById(Long id);

    SysResource qryResourceRoot(@Param("appCode") String appCode);

    List<SysResource> getChildResourceListByParentId(@Param("appCode") String appCode, @Param("parentId") Long parentId);

    SysResource qryResourceByResourceCodeAndAppCode(@Param("resourceCode") String resourceCode, @Param("appCode") String appCode);

    Long qryResourceRootId(@Param("appCode") String appCode);

    List<ResourceResVO> getChildResourceListByParentIdForSub(@Param("appCode") String appCode, @Param("roleIds") List<Long> roleIds, @Param("parentId") Long parentId);
}
